//system(LED_ON);
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <string>
using namespace std;
#include <iostream>


int calcHdlcAddrFromExp(string meterNo,string exp,char n='n')
{
    string ret;
    ret.reserve(128);
    ret.append("echo \"");
    for(auto ch:exp)
    {
        if(ch=='n')
            ret.append(meterNo);
        else
            ret.push_back(ch);
    }
    ret.append("\" |bc");

    FILE *fstream = NULL;      
    char buff[34];    
    memset(buff, 0, sizeof(buff));   

    if(NULL == (fstream = popen(ret.c_str(),"r")))      
    {          
        return 0;      
    }   
    if(NULL == fgets(buff, sizeof(buff), fstream)) 
    {  
        return 0;
    }  
    pclose(fstream);
    buff[sizeof(buff)-1]='\0';
    return atoi(buff); 
}



int main(int argc, char const *argv[])
{
    string exp="1+5";
    string n="123";
    cout<<calcHdlcAddrFromExp(n,exp)<<endl;
    /* code */
    return 0;
}
